﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using compshop.Infrastructure.CompShopDataService;
using compshop.Infrastructure;
using compshop.Modules.ListOfSuppliers.View;
namespace compshop.Modules.ListOfSuppliers.Presenter
{
  public  class SuppliersListPresenter
    {
        private CompShopEntities compShopDataContext;
        public IViewSuppliersList View { set; get; }
        private EventsManager eventsManager;
        public SuppliersListPresenter(EventsManager eventManager)
        {

            compShopDataContext = CompShopEntitiesContext.GetInstance();

            SuppliersList = compShopDataContext.Suppliers.ToList();
            eventsManager = eventManager;
            eventsManager.Presenter = this;
            eventsManager.Subscribe();
        }

        public List<Supplier> SuppliersList { set; get; }

        public void AddSupplier()
        {
            EditSupplierView editWindow = new EditSupplierView();
            editWindow.ShowDialog();
            if (editWindow.DialogResult == true)
            {
                compShopDataContext.AddToSuppliers(editWindow.supplier);
                compShopDataContext.SaveChanges();
                SuppliersList.Add(editWindow.supplier);
            }
        }
        public void EditSupplier(Supplier edittingSupplier)
        {
            EditSupplierView editWindow = new EditSupplierView(edittingSupplier);
            editWindow.ShowDialog();
            if (editWindow.DialogResult == true)
            {
                compShopDataContext.UpdateObject(editWindow.supplier);
                compShopDataContext.SaveChanges();
            }
        }
        #region Publishers

        
        #endregion

        #region Handlers


        #endregion
    }
}
